<html>
<head><meta charset="utf-8"><title>Places to set target-cpu · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html">Places to set target-cpu</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240661963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240661963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240661963">(May 28 2021 at 21:21)</a>:</h4>
<p>Hey, I was skmming over <a class="stream-topic" data-stream-id="246057" href="/#narrow/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host">#t-cargo &gt; target-cpu=native for host</a> and I wanted to double-check my understanding</p>



<a name="240662126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240662126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240662126">(May 28 2021 at 21:23)</a>:</h4>
<p>My inference is that one cannot set <code>target-cpu</code> settings via entries under <code>[profile]</code></p>



<a name="240662253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240662253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240662253">(May 28 2021 at 21:25)</a>:</h4>
<p>and instead, as of today, one needs to find ways to channel that info via RUSTFLAGS (or various cargo features that end up turning into RUSTFLAGS, like <a href="https://doc.rust-lang.org/cargo/reference/config.html#targettriplerustflags">target triple rustflags</a></p>



<a name="240663059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240663059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240663059">(May 28 2021 at 21:34)</a>:</h4>
<p>so, is that true?</p>



<a name="240663069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240663069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240663069">(May 28 2021 at 21:35)</a>:</h4>
<p>And, is that good enough?</p>



<a name="240663096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240663096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240663096">(May 28 2021 at 21:35)</a>:</h4>
<p>That is correct.</p>



<a name="240663111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240663111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240663111">(May 28 2021 at 21:35)</a>:</h4>
<p><a href="https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags"><code>build.rustflags</code></a> contains documentation for the 3 different ways to pass rustflags.</p>



<a name="240663127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240663127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240663127">(May 28 2021 at 21:35)</a>:</h4>
<p>I admit that I haven’t followed the work in this area too closely. Some people in the past have advised <a href="https://internals.rust-lang.org/t/policies-around-default-cpu-architecture/9142">changing the defaults</a> so we don’t leave performance on the ground for 99% of the developers</p>



<a name="240663251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240663251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240663251">(May 28 2021 at 21:37)</a>:</h4>
<p>Yea, the defaults are pretty conservative.</p>



<a name="240663271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240663271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240663271">(May 28 2021 at 21:37)</a>:</h4>
<p>and I’m guess I’m wondering whether that is the right answer (i.e. require zero effort from developers, at cost of surprising a few), or if we can find ways to make it smoother.</p>



<a name="240664295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240664295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240664295">(May 28 2021 at 21:47)</a>:</h4>
<p>I am a little out of my depth. So salt as needed. I don't think we can change the meaning of an existing target, or people that are picking it intentionally will be broken. But I wonder if we can change the detection, like if I use stock <code>cargo build</code> can it use <code>"x86_64-v3"</code> where it uses <code>"x86_64"</code> now.</p>



<a name="240664891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240664891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240664891">(May 28 2021 at 21:54)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> Did you have ideas on how to make it smoother?</p>



<a name="240665010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240665010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240665010">(May 28 2021 at 21:55)</a>:</h4>
<p>I was originally thinking along the lines of having a target_cpu setting</p>



<a name="240665041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240665041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240665041">(May 28 2021 at 21:55)</a>:</h4>
<p>But now I’m wondering more about <span class="user-mention" data-user-id="120179">@Eh2406</span> ‘s suggestion</p>



<a name="240665130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240665130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240665130">(May 28 2021 at 21:56)</a>:</h4>
<p>Or, even just issuing a diagnostic when it’s not set at all, and listing what targets one might use for the given host</p>



<a name="240666405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240666405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240666405">(May 28 2021 at 22:13)</a>:</h4>
<p>A <code>target-cpu</code> for profiles or targets?  Like</p>
<div class="codehilite" data-code-language="TOML"><pre><span></span><code><span class="c1"># instead of this:</span>
<span class="k">[build]</span>
<span class="n">rustflags</span> <span class="o">=</span> <span class="k">['-C', 'target-cpu=native']</span>

<span class="c1"># have this:</span>
<span class="k">[build]</span>
<span class="n">target-cpu</span> <span class="o">=</span> <span class="s">'native'</span>

<span class="c1"># or if you want something more specific</span>
<span class="k">[target.'cfg(target_arch="x86_64")']</span>
<span class="n">target-cpu</span> <span class="o">=</span> <span class="s">'skylake'</span>
</code></pre></div>
<p>Doing that could make it marginally easier to set.</p>
<p>Having target-aware profiles has also been a requested feature a few times (<a href="https://github.com/rust-lang/cargo/issues/4897">https://github.com/rust-lang/cargo/issues/4897</a>).  It might be nice to have it that way, too.  Having as part of the profile might give it more visibility, too.</p>
<p>I'm not sure how a warning could work, otherwise it would be very noisy (a warning on everyone's project).</p>
<p>I'm not really sure the default can be safely changed.  And even if the default is bumped, it would still need to be more conservative than what most users would benefit from.</p>
<p>Unfortunately I can't think of too many ideas on how to make this more visible.  We could maybe give more emphasis on things like nnethercote's <a href="https://nnethercote.github.io/perf-book/build-configuration.html#using-cpu-specific-instructions">performance book</a>.  We could add more documentation about creating production builds.</p>
<p>Also, I'm not 100% clear on the <a href="https://github.com/rust-lang/rust/issues/64609">soundness issue</a>.  I think it should be relatively safe to set target-cpu/target-features as long as everything uses the same settings.  Isn't the extern "C" interface always the same regardless of those settings?</p>



<a name="240666723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240666723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240666723">(May 28 2021 at 22:18)</a>:</h4>
<p>Another thing I would be concerned of is setting to anything other than "native" is hard to do correctly.  For example, if you are deploying to some cloud environment, if you are lucky you can figure out what all CPUs are used, but then how do you map that to the <code>target-cpu</code> or <code>target-feature</code> flags?  It takes a fair bit of research to figure that out.</p>



<a name="240666893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240666893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240666893">(May 28 2021 at 22:20)</a>:</h4>
<p>And it can also be really hard to know if any particular project will benefit from various target-features or cpu settings.</p>



<a name="240667582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240667582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240667582">(May 28 2021 at 22:30)</a>:</h4>
<p>The cloud case is a good one to discuss. Eg an individual developer may indeed not know the right setting. But profiles can be composed in some manner, right? (Or maybe that’s just config files that can be composed?) either way, AWS could provide a file that describes the minimum capabilities of its x86_64 EC2 instances. Likewise Microsoft Azure could do the same.</p>



<a name="240667759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240667759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240667759">(May 28 2021 at 22:33)</a>:</h4>
<p>(I do like the mock up you give. Giving it a first class entry will<br>
Inherently give it more visibility, IMO. If it’s only RUSTFLAGS, then some users will never touch it, regarding it to be dark magic</p>



<a name="240667849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240667849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jon Gjengset <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240667849">(May 28 2021 at 22:34)</a>:</h4>
<p>Another reason why RUSTFLAGS isn't an idea venue for controlling this is <a href="https://github.com/rust-lang/cargo/issues/5376">https://github.com/rust-lang/cargo/issues/5376</a> — it doesn't compose very nicely.</p>



<a name="240670143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670143">(May 28 2021 at 23:09)</a>:</h4>
<p>setting specific target-cpu values isn't all that useful in practice because it only affects instruction scheduling (AFAIK) for values that aren't <code>native</code>.</p>



<a name="240670161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670161">(May 28 2021 at 23:09)</a>:</h4>
<p>giving people way to set target-features they want to target would be much more important IMHO.</p>



<a name="240670221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670221">(May 28 2021 at 23:10)</a>:</h4>
<p>Really? Target-cpu doesn't set features based on that CPU?</p>



<a name="240670241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670241">(May 28 2021 at 23:10)</a>:</h4>
<p>I had assumed it was the equivalent of -march, not -mtune.</p>



<a name="240670326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670326">(May 28 2021 at 23:12)</a>:</h4>
<p>hm, <em>verifies</em></p>



<a name="240670363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670363">(May 28 2021 at 23:13)</a>:</h4>
<p>Not doubting, just really surprised.</p>



<a name="240670515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670515">(May 28 2021 at 23:16)</a>:</h4>
<p>I recall somehow arriving at that conclusion when working on a certain major perf regression that we had with -Ctarget-cpu=native.</p>



<a name="240670596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670596">(May 28 2021 at 23:16)</a>:</h4>
<p>we do set the target features explicitly for the <code>target-cpu=native</code> but we can't really do the same for other target-cpu values.</p>



<a name="240670690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670690">(May 28 2021 at 23:18)</a>:</h4>
<p>The fact that the similar regression was not visible with other target-cpu values suggested to me at that time that they don't end up enabling target-features that are applicable to those. And it isn't always clear what instructions are available for the given family – e.g. skylake can mean many different feature sets.</p>



<a name="240670751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670751">(May 28 2021 at 23:19)</a>:</h4>
<p>I'm pretty certain that all target-cpu settings includes default sets for target-features.</p>



<a name="240670965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240670965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240670965">(May 28 2021 at 23:23)</a>:</h4>
<p>Yeah, turns out I was wrong, setting target-cpu does enable the features applicable to that family.</p>



<a name="240671222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240671222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240671222">(May 28 2021 at 23:29)</a>:</h4>
<p>I believe the defaults for each x86 cpu are defined <a href="https://github.com/rust-lang/llvm-project/blob/39c5555872cc5d379cc3535a31dc0cdac969466f/llvm/lib/Support/X86TargetParser.cpp#L118-L286">here</a>.  It would be nice if those were documented, but I'm uncertain if they are guaranteed to be stable.</p>



<a name="240671322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240671322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240671322">(May 28 2021 at 23:30)</a>:</h4>
<p>I would assume any changes would be a bug, or maybe adding features that haven't been implemented.</p>



<a name="240671434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240671434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240671434">(May 28 2021 at 23:33)</a>:</h4>
<p>It's also not been really clear how flags like <code>-C target-cpu</code> will interact with different backends.  Like if we document that you can pass <code>znver3</code>, does that documentation need to say those CPUs are only for the LLVM backend?</p>



<a name="240949657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240949657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240949657">(Jun 01 2021 at 14:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu/near/240670161">said</a>:</p>
<blockquote>
<p>giving people way to set target-features they want to target would be much more important IMHO.</p>
</blockquote>
<p>I’m curious, <span class="user-mention" data-user-id="123586">@nagisa</span> , if you still stand by this statement given the correction about how <code>target-cpu</code> behaves? (I’m sitting here wondering if the ideal interface is for people to list out the minimal set features they expect to be present, or if the right interface is a way to say “here are all the cpu variants I expect to run on. Compiler, figure out the intersection of all their feature sets.")</p>



<a name="240949767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240949767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240949767">(Jun 01 2021 at 14:26)</a>:</h4>
<p>that is, which of the two modes of operation is better for the end-developer to use? Or should we offer both options?</p>



<a name="240960472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240960472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240960472">(Jun 01 2021 at 15:35)</a>:</h4>
<p>I still believe target_features are way more important but i do understand people don't want to go through the hassle. The reason I believe so is because certain CPU families don't do very well in precisely describing the targeted hardware.</p>



<a name="240960909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240960909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240960909">(Jun 01 2021 at 15:38)</a>:</h4>
<p>See e.g. <a href="https://github.com/rust-lang/rust/issues/44036">https://github.com/rust-lang/rust/issues/44036</a> re hassle, even though you can already do that with target_features.</p>



<a name="240960997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240960997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240960997">(Jun 01 2021 at 15:39)</a>:</h4>
<p>also if we end up giving users convenient ways to specify target-cpus I think we should give it the same treatment as we do for target-features – e.g. I can imagine us not wanting to expose and support all of the target-cpus that LLVM may think of adding to their codebase.</p>



<a name="240961291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240961291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240961291">(Jun 01 2021 at 15:41)</a>:</h4>
<p>Curiously I can't find anymore any open issues for <code>-Ctarget-cpu=skylake</code> not being a baseline of all skylakes.</p>



<a name="240983672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240983672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240983672">(Jun 01 2021 at 18:23)</a>:</h4>
<p>FWIW I somewhat painstakingly went through the process of manually finding the intersection of features supported on the CPU’s I cared about for my work projects, so a way to make that easier would be great</p>



<a name="240989976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/240989976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#240989976">(Jun 01 2021 at 19:14)</a>:</h4>
<p>as a general programmer providing library code to other people, i generally think in terms of target_feature.</p>
<p>as a binary developer i usually think about specific target cpus i might want to run my program on.</p>
<p>so both approaches are useful based on who you are.</p>



<a name="241061775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241061775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241061775">(Jun 01 2021 at 19:18)</a>:</h4>
<p>I <em>do</em> think we should have convenient ways to specify target-feature, but I also think most of the time target-cpu seems easier. (And it'll be even easier on x86 with the new architecture "levels" like <code>x86_64-v3</code>).</p>



<a name="241070155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241070155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241070155">(Jun 01 2021 at 20:23)</a>:</h4>
<p>maybe for some people.</p>
<p>Like i honestly have no idea what cpu i have other than "it's 6 cores and does avx2". And most people know less than that about their machine.</p>
<p>I'm not against the idea but i think you're maybe "too informed" to be understanding how the common masses approach the situation.</p>



<a name="241070328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241070328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241070328">(Jun 01 2021 at 20:25)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> I'm not trying to suggest that <em>either</em> is easy. Just that on a relative scale, it seems easier to say "this CPU" than to say "my CPU has these two-dozen target features".</p>



<a name="241070389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241070389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241070389">(Jun 01 2021 at 20:25)</a>:</h4>
<p>Also, we should really provide more tool assistance for that problem; I'd love to have an option that tells the compiler to do the detection it'd do for <code>target-cpu=native</code> and then print the equivalent options.</p>



<a name="241070820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241070820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241070820">(Jun 01 2021 at 20:28)</a>:</h4>
<p>That would allow logging that output on container start up. Then it is a simple query to decide if we can tern on some flage given the fleate we are running on.</p>



<a name="241070846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241070846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241070846">(Jun 01 2021 at 20:29)</a>:</h4>
<p>If you get a printout saying "you have x86_64-v3 plus target features x and y", that makes it easier to say "I want x86_64-v3 but I can't count on x and y".</p>



<a name="241071259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241071259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241071259">(Jun 01 2021 at 20:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu/near/241070389">said</a>:</p>
<blockquote>
<p>Also, we should really provide more tool assistance for that problem; I'd love to have an option that tells the compiler to do the detection it'd do for <code>target-cpu=native</code> and then print the equivalent options.</p>
</blockquote>
<p>Does <code>rustc --print=cfg -Ctarget-cpu=native | grep target_feature</code> roughly do that?</p>



<a name="241071808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241071808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241071808">(Jun 01 2021 at 20:36)</a>:</h4>
<p>i have a helper (written in fish-shell) for this purpose, which prints out the cfgs and the target-json (using nightly, a manually specified toolchain, or RUSTC_BOOTSTRAP unless you tell it not to). <a href="https://github.com/thomcc/fish-config/blob/main/functions/target.fish#L42-L46">https://github.com/thomcc/fish-config/blob/main/functions/target.fish#L42-L46</a> (link is to the help text). probably not useful to anybody who uses fish-shell, but i've found it very helpful in figuring out these sorts of things</p>



<a name="241071821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241071821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241071821">(Jun 01 2021 at 20:36)</a>:</h4>
<p><span class="user-mention" data-user-id="120518">@Eric Huss</span> No, not exactly. That just lists all the features, not the CPU. I'd love to have groups of options implied by a target CPU transformed into a target CPU option, and then just list the target_feature options that aren't implied by that CPU.</p>



<a name="241071840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241071840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241071840">(Jun 01 2021 at 20:36)</a>:</h4>
<p>hm, oh, i see</p>



<a name="241071841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241071841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241071841">(Jun 01 2021 at 20:36)</a>:</h4>
<p>(It <em>is</em> helpful, though.)</p>



<a name="241071855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241071855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241071855">(Jun 01 2021 at 20:37)</a>:</h4>
<p>(nevermind, what i described is different)</p>



<a name="241072079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241072079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241072079">(Jun 01 2021 at 20:38)</a>:</h4>
<p>cargo print-target-feature</p>



<a name="241081634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241081634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241081634">(Jun 01 2021 at 22:04)</a>:</h4>
<p>Ideally it also has a way to pick the common denominator from results from multiple machines so that you don't have to do that manually.</p>



<a name="241092602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Places%20to%20set%20target-cpu/near/241092602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Places.20to.20set.20target-cpu.html#241092602">(Jun 02 2021 at 00:30)</a>:</h4>
<p>I will note, though, that having a little utility for listing target features is fairly easy in rust: you just print out is_x86_feature_detected for each of the target feature you care about. the woes of having a standard library that's eventually becoming useful all on its own!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>